hysop.tools.handle module¶
- class hysop.tools.handle.Handle(handle, **kargs)[source]¶
Bases:
object
Generic class to encapsulate various objects (‘handles’).
Build a Handle from a handle instance.
Raise ValueError if given handle is None. Raise TypeError if given handle does not match targetted handle type.
- class hysop.tools.handle.RegisteredObject(register_object=True, tag_prefix=None, tag_postfix=None, tag_formatter=None, **kwds)[source]¶
Bases:
TaggedObject
Generic class to manage unique immutable object instances (like Topologies, Domains and so on). Has a TaggedObject interface but each tag id is unique among all objects of the same class created with the exact same hashed __new__ arguments.
Initialize this object. If self._initialized was already set to True, raise a RuntimeError. Else, set self._initialized to True.
- static __new__(cls, register_object=True, tag_prefix=None, tag_postfix=None, tag_formatter=None, **kwds)[source]¶
Creates and return a RegisteredObject and assign a unique id if and only if a previous object was not already created with the exact same keywords arguments (modulo hashing).
If the object was already created, it’s instance is simply returned.
- All keyword arguments contained in **kwds have to be immutable:
- *Arguments cannot be None (you have to set all default arguments
in child classes __new__).
*Lists should be replaced by tuples. *Sets should be replaced by frozensets. *Dictionaries should be internally stored as tuple of tuples (use dict.items()). *np.ndarray should be set read-only (by using npw.set_readonly). *MPI.Intracomm and MPI.Intercomm are hashed with their python object id,
child classes are responsible for the immutability of those parameters.
Initialization should be done if and only if self._initialized is False.
- /!Always pass current class __new__ arguments to the base class __new__.
Full modification input keywords arguments should be done in __new__, before base class __new__ call.
All input keyword arguments should be formatted to the exact same immutable type and default values should be precomputed, otherwise two different RegisteredObject might be created even if the final objects are the same after initialization.
Full initialization of object should be done in __new__ after base class __new__ guarded by initialization safe guard (if obj.obj_initialized).
[modify original **kwds to immutable objects] obj = super(CurrentClass,cls).__new__(cls, [current __new__ **kwds], **kwds) if not obj.obj_initialized:
[initialize returned object (which is a new instance)]
return obj
- /!Only define __init__ if absolutely required (for multiple inheritance of custom
objects for example and if you know what you are doing). __init__ default arguments will not be the ones from __new__ if modified.
self.__init__(**kwds) is always called, even if the object was already created, a safeguard should be set in each child class __init__ method, if present. User arguments are passed as user supplied from __new__ to __init__. This means that all default arguments modified in __new__ are not passed modified to __init__ and thus that all class parameters should be set in __new__. When using __init__, its arguments should not be used.
- property obj_initialized¶
Return the object initialization state.
- class hysop.tools.handle.TaggedObject(tag_prefix=None, tag_postfix=None, tag_formatter=None, tagged_cls=None, **kwds)[source]¶
Bases:
object
Generic class to count object instances and associate a tag to it. A tag is basically the id of the object instance formatted to a string. This make it simpler to visually identify objects compared to python object id (for logging or debug purposes).
Initialize a TaggedObject with a tag prefix/postfix/formatter, all optional.
- static __new__(cls, tag_prefix=None, tag_postfix=None, tag_formatter=None, tagged_cls=None, **kwds)[source]¶
Create a TaggedObject object and assign it an id.
- property full_pretty_tag¶
Get the formatted tag of this object as a string. This is an instance identifier along with a class identifier.
- property full_tag¶
Get the formatted tag of this object as a string. This is an instance identifier along with a class identifier.
- property id¶
Return the id of the present object tag id. This is not the same as the python object id.
- property pretty_tag¶
Get the formatted pretty tag of this object as a string. This is an instance identifier
- property tag¶
Get the formatted tag of this object as a string. This is an instance identifier
- class hysop.tools.handle.TaggedObjectView(obj_view=None, **kwds)[source]¶
Bases:
object
View on a TaggedObject, just forwards tag and id for views.
- property full_pretty_tag¶
Unique tag of the underlying object view with cls information.
- property full_tag¶
Unique tag of the underlying object view with cls information.
- property id¶
Unique id of the underlying object view.
- property pretty_tag¶
Unique pretty tag of the underlying object view.
- property tag¶
Unique tag of the underlying object view.